package org.example.game.biweekly.game138;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @Description: TODO
 * @Author wyatt
 * @Data 2024/08/03 20:46
 */
public class Solution003 {

    public static void main(String[] args) {
        System.out.println(new Solution003().minDamage(4, new int[]{1,2,3,4}, new int[]{4,5,6,8}));
    }


    /**
     * @Description:
     * 先打伤害最高的
     * 后面打的 会累计时间伤害
     *
     * 同伤害的， 先打健康度低的
     *
     * @auther: wyatt
     * @date: 23:01 2024-08-31
    */
    public long minDamage(int power, int[] damage, int[] health) {
        Map<Integer, List<Integer>> damageMap = new HashMap<>();

        for (int i = 0; i < damage.length; i++) {
            damageMap.putIfAbsent(damage[i], new ArrayList<>());
            damageMap.get(damage[i]).add(health[i]);
        }

        List<Integer> sortDamageList = new ArrayList<>(damageMap.keySet());
        sortDamageList = damageMap.keySet().stream().sorted(Comparator.reverseOrder()).collect(Collectors.toList());

        long time = 0L;
        long minDamage = 0L;

        for (Integer damageIndex : sortDamageList) {
            List<Integer> sortHealthList = damageMap.get(damageIndex).stream().sorted().collect(Collectors.toList());
            for (Integer healthIndex : sortHealthList) {
                time += healthIndex/power + (healthIndex%power > 0 ? 1 : 0);
                minDamage += (damageIndex * time);
                System.out.println(damageIndex + ", " + time + " , "+ minDamage);
            }
        }

        return minDamage;
    }

}
